//@author A0097466M

#include "ParserTest.h"
TEST_F(ParserTest, ParserTest1){
	string rawInputTask1 = "[description][date][1000][2300][school]";
	string rawInputTask2 = "[description][18 Sep][][][school]"; 
	string rawInputTask3 = "[description][18 Sep][1000][][school]";
	string rawInputTask4 = "[description][18 Sep][][1400][school]";
	string rawInputTask5 = "[description][18 Sep][1000][1000][school]";
	string rawInputTask6 = "[description][18 Sep][1000][0800][school]";

	Task processedTask1 = parser.parseTask(rawInputTask1);
	Task processedTask2 = parser.parseTask(rawInputTask2);
	Task processedTask3 = parser.parseTask(rawInputTask3);
	Task processedTask4 = parser.parseTask(rawInputTask4);
	
	string expectedTask1 ="[description][11112013][1000][2300][school]";
	string expectedTask2 = "[description][18092013][0000][2359][school]";
	string expectedTask3 = "[description][18092013][1000][2359][school]";
	string expectedTask4 = "[description][18092013][0000][1400][school]";

	string reverseTask1 = parser.reverseParse(processedTask1);
	string reverseTask2 = parser.reverseParse(processedTask2);
	string reverseTask3 = parser.reverseParse(processedTask3);
	string reverseTask4 = parser.reverseParse(processedTask4);

	ASSERT_EQ(expectedTask1, reverseTask1);
	ASSERT_EQ(expectedTask2, reverseTask2);
	ASSERT_EQ(expectedTask3, reverseTask3);
	ASSERT_EQ(expectedTask4, reverseTask4);

	ASSERT_ANY_THROW(parser.parseTask(rawInputTask5));
	ASSERT_ANY_THROW(parser.parseTask(rawInputTask6));
}

TEST_F(ParserTest, ParserTest2) {
	string rawTime1 = "1000";
	string rawTime2 = "2.30pm";
	string rawTime3 = "12pm";
	string rawTime4 = "2500";
	string rawTime5 = "2..40..";
	string rawTime6 = "";
	string rawTime7 = "start time";
	string rawTime8 = "end time";

	string expectedTime1 = "1000";
	string expectedTime2 = "1430";
	string expectedTime3 = "1200";
	string expectedTime6 = "0000";
	string expectedTime7 = "0000";
	string expectedTime8 = "2359";

	rawTime1 = parser.processRawTime(rawTime1, false);
	rawTime2 = parser.processRawTime(rawTime2,false);
	rawTime3 = parser.processRawTime(rawTime3,false);
	rawTime6 = parser.processRawTime(rawTime6,true);
	rawTime7 = parser.processRawTime(rawTime7,true);
	rawTime8 = parser.processRawTime(rawTime8,false);
	
	ASSERT_EQ(expectedTime1, rawTime1);
	ASSERT_EQ(expectedTime2, rawTime2);
	ASSERT_EQ(expectedTime3, rawTime3);

	ASSERT_ANY_THROW(parser.processRawTime(rawTime4, false));
	ASSERT_ANY_THROW(parser.processRawTime(rawTime5, false));
	
	ASSERT_EQ(expectedTime6, rawTime6);
	ASSERT_EQ(expectedTime7, rawTime7);
	ASSERT_EQ(expectedTime8, rawTime8);
}

TEST_F(ParserTest, ParserTest3){
	string rawDate1 = "09122013";
	string rawDate2 = "9 Dec";
	string rawDate3 = "9 Dec 2013";
	string rawDate4 = "9/12";
	string rawDate5 = "9/12/2013";
	

	string rawDate6 = "40132014";
	string rawDate7 = "54464548454";
	string rawDate8 = "37 Feb";
	string rawDate9 = "//2013";
	string rawDate10 = "tomorrow";
	string rawDate11 = "saturday";
	string rawDate12 = "next sat"; 
	string rawDate13 = "next";


	string expectedDate1 = "09122013";
	string expectedDate2 = "12112013";
	string expectedDate3 = "16112013";
	string expectedDate4 = "23112013";

	rawDate1 = parser.processRawDate(rawDate1);
	rawDate2 = parser.processRawDate(rawDate2);
	rawDate3 = parser.processRawDate(rawDate3);
	rawDate4 = parser.processRawDate(rawDate4);
	rawDate5 = parser.processRawDate(rawDate5);
	rawDate10 = parser.processRawDate(rawDate10);
	rawDate11 = parser.processRawDate(rawDate11);
	rawDate12 = parser.processRawDate(rawDate12);
	
	ASSERT_EQ(expectedDate1, rawDate1);
	ASSERT_EQ(expectedDate1, rawDate2);
	ASSERT_EQ(expectedDate1, rawDate3);
	ASSERT_EQ(expectedDate1, rawDate4);
	ASSERT_EQ(expectedDate1, rawDate5);
	
	ASSERT_ANY_THROW(parser.processRawDate(rawDate6));
	ASSERT_ANY_THROW(parser.processRawDate(rawDate7));
	ASSERT_ANY_THROW(parser.processRawDate(rawDate8));
	ASSERT_ANY_THROW(parser.processRawDate(rawDate9));
	
	ASSERT_EQ(expectedDate2, rawDate10);
	ASSERT_EQ(expectedDate3, rawDate11);
	ASSERT_EQ(expectedDate4, rawDate12);
	
	ASSERT_ANY_THROW(parser.processRawDate(rawDate13));

}

TEST_F(ParserTest, ParserTest4){
	string invalidDate1 = "35012013";
	string invalidDate2 = "35122013";

	invalidDate1 = parser.normalizeInvalidDate(invalidDate1);
	invalidDate2 = parser.normalizeInvalidDate(invalidDate2);

	string expectedDate1 = "04022013";
	string expectedDate2 = "04012014";

	ASSERT_EQ(expectedDate1, invalidDate1);
	ASSERT_EQ(expectedDate2, invalidDate2);
}

